import { axiosMock, delayFn, randArrItem } from '@/services/axiosMock'
import { IAttachmentListItem } from '../interface'

let count = 0
const img1 = `https://fba-srm.oss-cn-hongkong.aliyuncs.com/1734260133964_test1.png`
const img2 = `https://fba-srm.oss-cn-hongkong.aliyuncs.com/1734260167384_test2.png`

axiosMock('default', mock => {
  // 获取运单附件列表
  mock.onPost(`/tmsapi/attach/list`).reply(
    delayFn(600, () => {
      const idPrefix = ++count
      return {
        success: true,
        data: {
          attachListResultParams: Array(randArrItem([10, 20, 30]))
            .fill(null)
            .map((_item, index) => {
              const id = +`${idPrefix}${index + 1}`
              return {
                fileId: id,
                fileUrl: randArrItem([img1, img2], 0.1),
                fileName: randArrItem(
                  [`附件名附件名附件名${id}`, `附件名附件名附件名附件名附件名附件名附件名附件名附件名${id}`],
                  0.1,
                ),
                sourceType: randArrItem([1, 2, 3], 0.1),
                sourceId: randArrItem([`来源单据号${id}`], 0.1),
                fileType: randArrItem([1, 2, 3, 4, 5, 6], 0.1),
                uploadBy: randArrItem([`上传人${id}`], 0.1),
                uploadAt: randArrItem(['2023-11-16 12:12:12', '2024-11-16 12:12:12'], 0.1),
                deleteFlag: randArrItem([0, 1], 0.1),
              } satisfies IAttachmentListItem
            }),
        },
      }
    }),
  )

  // 修改运单附件类型
  mock.onPost(`/tmsapi/waybill_record/updateWaybillAttachInfo`).reply(
    delayFn(600, () => {
      return {
        success: true,
      }
    }),
  )

  // 运单附件删除
  mock.onPost(`/tmsapi/waybill_record/deleteWaybillAttach`).reply(
    delayFn(600, () => {
      return {
        success: true,
      }
    }),
  )
})
